﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.LambWeaningCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.LambWeaningHandler
{
    public class LambWeaningCreateHandler:IRequestHandler<LambWeaningCreateCommand,Results<int>>
    {
        private readonly ILambWeaningService _lambService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="lambService"></param>
        /// <param name="mapper"></param>
        public LambWeaningCreateHandler(ILambWeaningService lambService,IMapper mapper)
        {
            _lambService = lambService;
            _mapper = mapper;
        }

        /// <summary>
        /// 羔羊断奶新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(LambWeaningCreateCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<List<LambWeaning>>(request.LambList);
            var entitylist = await _lambService.LambWeaningAdd(result);
            return Results<int>.DataResult(entitylist);
        }




    }
}
